iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 24
0
Kubernetes

從Docker到Kubernetes-新手入門筆記系列 第 24

Day24 Cluster IP Service-只有Node內才看得到

  • 分享至 

  • xImage
  •  

到目前為止Service Type都是NodePort,VM外要存取pod都是透過kube-proxy導到NodePort指定的port,production時處理外部的Request由Ingress Service來將request導向Node內部,Node裡需要有相互可以溝通而且沒有對外expose的Service,這種只能Node內可以溝通的Service Type為ClusterIP,建立跟之前docker-compose類似的架構

  • Frontend
  • API Server
  • Database Server
  • Redis

建立API Server ClusterIP Service

先以API Server為例,建立ClusterIP yaml設定檔

# nestjsapi-clusterip-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nestjsapi-clusterip-service
spec:
  type: ClusterIP 
  selector:
    component: api
  ports: 
    - port: 5000 # port exposed to node network
      targetPort: 5000 # link port to container
      # nodePort no longer required

先刪除已經建立的deployment, services移除

kubectl get deployment

kubectl delete deployment deploymentName

kubectl get service

kubectl delete service serviceName

確認沒有running的pod

kubectl get pod

套用剛剛建立的cluster ip設定檔

kubectl apply -f nestjsapi-clusterip-service.yaml

建立Frontend Deployment & ClusterIP Service

建立frontend-deployemnt.yaml

# frontend-deployemnt.yaml
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: frontend-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: frontend
  template:
    metadata:
      labels:
        component: frontend
    spec:
      containers:
        - name: nestjsapi
          image: yirengoo/frontend
          ports:
            - containerPort: 4200

kubectl apply -f frontend-deployemnt.yaml

建立frontend-clusterip-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: frontend-clusterip-service
spec:
  type: ClusterIP
  ports:
    - port: 4200
      targetPort: 4200
  selector:
    component: frontend

kubectl apply -f frontend-clusterip-service.yaml

其餘部分明天繼續


上一篇
Day23-使用Deployment管理Pod/Containers(下)-更新image及Scaling
下一篇
Day25 Database Pod為什麼需要Volume
系列文
從Docker到Kubernetes-新手入門筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言